// 创建birds.js
var express = require('express')
var timeoutApi = express.Router()// 创建一个路由实例



// 中间件功能
timeoutApi.use(function timeLog (req, res, next) {
  console.log('Time: ', new Date().toLocaleString())
  next()
})
// 访问/putApi
timeoutApi.get('/', function (req, res) {
  
    console.log('zdy-----baseUrl：------>'+req.baseUrl)
    console.log('zdy-----headers：------>'+JSON.stringify(req.headers))
    console.log('zdy-----body：------>'+JSON.stringify(req.body))
    res.send(JSON.stringify(req.body))
})

// 访问/getPlus/:id
timeoutApi.get('/timeoutTest', function (req, res) {
  req.setTimeout(3000)//===========================TODO===============================================================================================
  // 获取参数
  let headers = req.headers ? JSON.stringify(req.headers) : '';
  let params = req.params ? JSON.stringify(req.params) : '';
  let query = req.query ? JSON.stringify(req.query) : '';
  console.log('params :----> ', params)
  console.log('query   :----> ', query)
  console.log('headers   :----> ', headers)
  setTimeout(() => {
    console.log('timeoutTest :---->返回结果 ')
    res.json({
        header: headers,
        params: params,
        query: query,
        method: req.method,
        url: req.originalUrl,
        msg: '服务器回复'
      })
  }, 100000);
})



module.exports = timeoutApi